/*
******************************************************************************************************* 
**  Copyright (C) 
**  All rights reserved. 
** 
**  FileName:			template_task.c
**  Description:	The module src file template
**  Author:       ZengDa 	 
**  Version				v0.1
**  Date:					2022-04-06
**	Function List
**  History:         
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/
#include "pretreatment.h"
//#include "claw485.h"
#include "CR100_scan.h"

//#ifdef USE_RFID_MODBUS
#include "rfid_modbus.h"
//#else
#include "RFID485.h"
//#endif

#include "rfid_modbus.h"
#include "foreach_plunger.h"
#include "misumi_claw.h"
/*
*********************************************************************************************************
*                                              宏定义
*********************************************************************************************************
*/
#define		PMT_TASK_STK_SIZE			1024
#define		PMT_TASK_MB_SIZE				32
#define		PMT_TASK_SENDLIST_MAX	 128

#define		PMT_SCH_TIMEOUT				2000
#define		PMT_ERR_THRESHOLD			0x80
/*
*********************************************************************************************************
*                                              变量定义
*********************************************************************************************************
*/
schedule_cb_t	g_pmt_cb;
extern drive_pwm_t drive_pwm_array[DC_MOTOR_NUM];
extern struct rt_mailbox		rt_eth_mb;

static struct rt_thread   	rt_pmt_tcb;
static char									pmt_task_stk[PMT_TASK_STK_SIZE];
static char									pmt_task_name[]="pmt task\0";
static char									pmt_task_mb_pool[PMT_TASK_MB_SIZE * 4];

static modbus_t m_modbus;
static plunger_t* p_plunger;
static uint8_t surface_motor_index;
/*
*********************************************************************************************************
*                                              函数声明
*********************************************************************************************************
*/
static void pmt_task_init(void);
static void pmt_task_process(void *p_arg);
static void pmt_sch_proc(uint32_t data);
static void pmt_act_start(pmt_action_t); 
static void pmt_act_finish(pmt_action_t);
static void plunger_status_callback(plunger_t* handle,plunger_event_t event);
static void modbus_recv_callback(struct MODBUS_T * p_handle,uint8_t* buff,uint16_t size);
void	btn_callback(signal_index_t index,signal_type_t edge);
static void pmt_calib_callback(protocol_cmd_t cmd,uint8_t* buff,uint16_t size);
static void	cr100_scan_callback(struct CR100*,uint8_t * buff,uint16_t size);
static void rfid_recv_callback(uint8_t * buff,uint16_t size,rfid_err_t err_code);
static void claw_poll(uint64_t tick);
static void disable_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
static void uninit_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
static void idle_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
static void schedule_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
static void calib_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
static void manual_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
static void switch_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
static void error_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg);
/*
*********************************************************************************************************
*	
*********************************************************************************************************
*/
void pmt_task_start(void)
{
	if(RT_EOK != rt_thread_init(&rt_pmt_tcb,
		pmt_task_name, 
		pmt_task_process,
		RT_NULL,
		pmt_task_stk,
		PMT_TASK_STK_SIZE,
		PMT_TASK_PRIO,
		RT_THREAD_TIME_SLICE))
	{
		Critical_Log("%s create failed!\r\n",pmt_task_name);
//		while(1){}
	}
	else
		rt_thread_startup(&rt_pmt_tcb);
}
static void pmt_task_init(void)
{
	memset(&g_pmt_cb,0,sizeof(schedule_cb_t));
	g_pmt_cb.p_tcb = &rt_pmt_tcb;
	g_pmt_cb.status = MOD_STATUS_UNINIT;
	g_pmt_cb.type = MOD_TYPE_SYNC;
	g_pmt_cb.sch_timeout = PMT_SCH_TIMEOUT;
	g_pmt_cb.period_offline = 0;
	g_pmt_cb.pfn_act_start = pmt_act_start;
	g_pmt_cb.pfn_act_finish = pmt_act_finish;

	if(RT_EOK != rt_mb_init(&g_pmt_cb.mailbox,
		"pmt mailbox",
		pmt_task_mb_pool,
		PMT_TASK_MB_SIZE,
		RT_IPC_FLAG_FIFO
		))
	{
		Critical_Log("%s create failed!\r\n",pmt_task_name);
	}
	if(LIST_ERR_NONE != list_create(&g_pmt_cb.send_list,PMT_TASK_SENDLIST_MAX,
											LIST_FIFO,&rt_act_mp))
	{
		Critical_Log("PMT task create send list failed!\r\n");
	}
	protocol_handler_register(CMD_HOME,pmt_calib_callback);
	protocol_handler_register(CMD_JOG,pmt_calib_callback);
	protocol_handler_register(CMD_CLAW,pmt_calib_callback);
	protocol_handler_register(CMD_CLAW_STATUS,pmt_calib_callback);
	protocol_handler_register(CMD_SCAN,pmt_calib_callback);
	protocol_handler_register(CMD_RFID,pmt_calib_callback);
	protocol_handler_register(CMD_RFID_WRITE,pmt_calib_callback);
	protocol_handler_register(CMD_PUMP,pmt_calib_callback);
	protocol_handler_register(CMD_VALVE,pmt_calib_callback);
	protocol_handler_register(CMD_SURFACE,pmt_calib_callback);
	protocol_handler_register(CMD_SUCK,pmt_calib_callback);
	protocol_handler_register(CMD_RESET_TIP,pmt_calib_callback);
	protocol_handler_register(CMD_LED,pmt_calib_callback);
	protocol_handler_register(CMD_MOTOR_DISABLE,pmt_calib_callback);
	protocol_handler_register(CMD_QURY_ENC,pmt_calib_callback);
	for(uint8_t i = 0;i< SIGNAL_TOTAL_NUM;i++)
	{
		signal_init(i,btn_callback);
	}
	valve_init();
	rt_thread_delay(3000);
#ifdef USE_STDL_PLUNGER
	bsp_plunger_init(plunger_status_callback);
	p_plunger = plunger_init(PLUNGER_ADDRESS);
#endif
	if(CLAW_OPENED != misumi_claw_init())
	{
		Critical_Log("Misumi claw init err!\r\n");
	}
	cr100_init(cr100_scan_callback);
	rt_thread_delay(10);
#ifdef USE_RFID_MODBUS
	if(RFID_MB_ERR_NONE != rfid_mb_init())
	{
		Error_Log("RFID modbus init err!\r\n");
	}
#else
	rfid485_init(rfid_recv_callback);
#endif
//	if(MODBUS_ERRNONE != modbus_init(&m_modbus,CLAW_UART_CHN,115200))
//	{
//		Critical_Log("modbus failed!\r\n");
//	}
//	m_modbus.pfn_recv_callback = modbus_recv_callback;
	rt_thread_delay(1000); /*�ȴ���צʱ��*/
//	claw_status_t status = misumi_claw_open();
//	if(CLAW_OPENED != status)
//	{
//		Error_Log("Misumi claw init errcode %d!\r\n",status);
//	}
//	uint32_t timeout = 0;
//	claw2 = claw_init(&m_modbus,CLAW_2_ADDRESS);
//	while(modbus_get_status(&m_modbus) != MODBUS_IDLE)
//	{
//		timeout++;
//		if(timeout == 100)
//		{
//			timeout = 0;
//			Critical_Log("Claw2 init failed!\r\n");
//			break;
//		}
//		rt_thread_delay(10);
//	}
	rt_thread_delay(50);/*������Ҫ���*/
//	claw1 = claw_init(&m_modbus,CLAW_1_ADDRESS);
//	while(modbus_get_status(&m_modbus) != MODBUS_IDLE)
//	{
//		timeout++;
//		if(timeout == 100)
//		{
//			timeout = 0;
//			Critical_Log("Claw1 init failed!\r\n");
//			break;
//		}
//		rt_thread_delay(10);
//	}
	rt_thread_delay(2000);
	for(uint8_t index = 0;index < MOTOR_NUM;index++)
	{
		motor_config(index,&g_pmt_cb,M_MODE_POS);
	}
	app_msg_send(MSG_ETH_EVENT,TCP_START,&rt_eth_mb);
	system_message_print();
}
/*
*********************************************************************************************************
*																					ģ�麯��
*********************************************************************************************************
*/

void	btn_callback(signal_index_t index,signal_type_t edge)
{
	uint16_t msg[2];
	msg[0] = index;
	if(edge == SIGNAL_POSEDGE)
	{
		msg[1] = 0;
		tcp_transfer_push(RPLY_BTN,msg,sizeof(msg));
	}
	if(edge == SIGNAL_NEGEDGE)
	{
		msg[1] = 1;
		tcp_transfer_push(RPLY_BTN,msg,sizeof(msg));
	}
}
static void plunger_status_callback(plunger_t* handle,plunger_event_t event)
{
	switch(event)
	{
		case PLUNGER_MOVE_CPLT:
			if(handle->p_status == PSTATUS_MOVING)
			{
				tcp_transfer_push(RPLY_SUCK,NULL,0);
			}
			else if(handle->p_status == PSTATUS_HOMING)
			{
				tcp_transfer_push(RPLY_RESET_TIP,NULL,0);
			}
			break;
		case PLUNGER_CAPACITY_EXCEED:
			motor_halt(surface_motor_index);
			motor_syn(surface_motor_index);
			plunger_capacity(handle,0);
			break;
		case PLUNGER_TIP_DROP:
			break;
		case PLUNGER_CATCH_ERR:
			break;
		default:break;
	}
}
static void rfid_recv_callback(uint8_t * buff,uint16_t size,rfid_err_t err_code)
{	
	uint16_t rtn;
	static char err[] = "RFID err code %d!\r\n";
	if(rfid_get_last_cmd() == RFID_READ)
	{
		if(err_code != RFID_ERR_NONE)
		{
			Trace_Log("RFID err code %d!\r\n",err_code);
	//		tcp_transfer_push(RPLY_RFID,err,sizeof(err));
			tcp_transfer_push(RPLY_RFID,NULL,0);
			return;
		}
		tcp_transfer_push(RPLY_RFID,buff,size);
	}
	else if(rfid_get_last_cmd() == RFID_WRITE)
	{
		rtn = rfid_get_size();
		if(err_code != RFID_ERR_NONE)
		{
			rtn = 0;
			Trace_Log("RFID err code %d!\r\n",err_code);
	//		tcp_transfer_push(RPLY_RFID,err,sizeof(err));
			tcp_transfer_push(RPLY_RFID_WRITE,&rtn,sizeof(rtn));
			return;
		}
		tcp_transfer_push(RPLY_RFID_WRITE,&rtn,sizeof(rtn));
	}
}
void	cr100_scan_callback(struct CR100* phandle,uint8_t * buff,uint16_t size)
{
	Trace_Log("CR100 scan get:\"%s\"\r\n",buff);
	tcp_transfer_push(RPLY_SCAN,buff,size);
	return;
}
static void modbus_recv_callback(struct MODBUS_T * p_handle,uint8_t* buff,uint16_t size)
{

}

static void pmt_calib_callback(protocol_cmd_t cmd,uint8_t* buff,uint16_t size)
{
	Trace_Log("Receive cmd %d;\r\n",cmd);
	/*rfid modbus 相关*/
	uint8_t * p_uint8;
	rfid_mb_err_t err;
	uint16_t write_size;
	
	int32_t enc_pos[MOTOR_NUM];
	
	led_cmd_t* p_led = (led_cmd_t*)buff;
	jog_cmd_t* p_cmd = (jog_cmd_t*)buff;
	pump_cmd_t* p_pump = (pump_cmd_t*)buff;
	claw_cmd_t* cmd_claw = (claw_cmd_t*)buff;
	claw_cmd_t rtn_claw;
//	claw_t* p_claw = NULL;
	claw_cmd_t claw_rply;
	claw_status_t claw_status;
	switch(cmd)
	{
		case CMD_HOME:
			motor_home(6);
			motor_home(4);
			motor_home(1);
			motor_home(3);
			motor_home(5);
			motor_home(2);
		
			motor_home(7);
			motor_home(0);
			motor_home(8);
		
			motor_home(9);
			motor_home(10);
			motor_home(11);
			msg_post(MSG_PMT_HOME_CPLT, NULL, &g_pmt_cb,&g_pmt_cb);
			break;
		case CMD_JOG:
			if(p_cmd->speed != 0)
			{
				motor_speed_ex(p_cmd->id,p_cmd->speed);
			}
			if(p_cmd->relative_pos == 1)
			{
				motor_syn(surface_motor_index);
				motor_step(p_cmd->id,DEFAULT_STEP,p_cmd->pos);
			}
			else
			{
				motor_pos_asyn(p_cmd->id,DEFAULT_POS,p_cmd->pos);
			}
			break;
		case CMD_CLAW:
			if(cmd_claw->claw_status == 0)
			{
				rtn_claw.claw_status = 0;
				claw_status = misumi_claw_open();
				if(claw_status == CLAW_OPENED)
					rtn_claw.claw_status = 0;
				else
				{
					Error_Log("Misumi claw errcode %d!\r\n",claw_status);
					rtn_claw.claw_status = 2;
				}
			}
			else if(cmd_claw->claw_status == 1)
			{
				rtn_claw.claw_status = 0;
				claw_status = misumi_claw_close();
				if(claw_status == CLAW_CATCHED)
					rtn_claw.claw_status = 1;
				else if(claw_status == CLAW_CLOSED)
					rtn_claw.claw_status = 0;
				else
				{
					Error_Log("Misumi claw errcode %d!\r\n",claw_status);
					rtn_claw.claw_status = 2;
				}
			}
			rtn_claw.claw_id = 0;
			tcp_transfer_push(RPLY_CLAW,&rtn_claw,sizeof(rtn_claw));
			break;
		case CMD_CLAW_STATUS:
			if(misumi_claw_status() == CLAW_CATCHED)
				claw_rply.claw_status = 1;
			else
				claw_rply.claw_status = 0;
			tcp_transfer_push(RPLY_CLAW_STATUS,&claw_rply,sizeof(claw_rply));
			break;
		case CMD_SCAN:
			cr100_start(CR100_SINGLE_SCAN);
			process_tmr(500,&g_pmt_cb);
			msg_post(MSG_SCAN_STOP, NULL, &g_pmt_cb,&g_pmt_cb);
			break;
		case CMD_RFID:
#ifdef USE_RFID_MODBUS
			/*上位机发下来的是byte长度*/
			write_size = *((uint16_t*)buff);
			p_uint8 = rfid_mb_read(write_size,&err);
			if(err == RFID_MB_ERR_NONE && p_uint8 != NULL)
			{
				tcp_transfer_push(RPLY_RFID,p_uint8,write_size);
			}
			else
			{
				/*errcode*/
				tcp_transfer_push(RPLY_RFID,NULL,0);
			}
#else
			rfid_process(1000,&g_pmt_cb,*((uint16_t*)buff));
			process_tmr(500,&g_pmt_cb);
			msg_post(MSG_RFID_STOP, NULL, &g_pmt_cb,&g_pmt_cb);
#endif
			break;
		case CMD_RFID_WRITE:
#ifdef USE_RFID_MODBUS
			write_size = *(1 + (uint16_t*)buff);
			err = rfid_mb_write(*((uint16_t*)buff),write_size,buff + 2 * sizeof(uint16_t));
			if(err == RFID_MB_ERR_NONE)
			{
				tcp_transfer_push(RPLY_RFID_WRITE,&write_size,sizeof(write_size)); /*成功返回两byte长度 否者返回零*/
			}
			else
			{
				/*errcode */
				write_size = 0;
				tcp_transfer_push(RPLY_RFID_WRITE,&write_size,sizeof(write_size));
			}
#else
			rfid_write(*((uint16_t*)buff),*(1 + (uint16_t*)buff),buff + 2 * sizeof(uint16_t));
//			rfid_process(1000,&g_pmt_cb,*((uint16_t*)buff));
			process_tmr(500,&g_pmt_cb);
			msg_post(MSG_RFID_STOP, NULL, &g_pmt_cb,&g_pmt_cb);
			break;
#endif
		case CMD_PUMP:
			if(*((uint16_t*)buff + 1))
			{
				if(p_pump->duty_cycle >= 1 && p_pump->duty_cycle <= 99)
				{
					dcm_array[p_pump->id].p_cfg->duty_cycle = p_pump->duty_cycle;
//					drive_pwm_array[p_pump->id].p_cfg->duty_cycle = p_pump->duty_cycle;
				}
				else
				{
//					drive_pwm_act(*((uint16_t*)buff),DRIVE_PWM_OPEN,&g_pmt_cb);
				}
				dcm_act(p_pump->id,DCM_OPEN,&g_pmt_cb);
			}
			else
			{
				dcm_act(p_pump->id,DCM_CLOSE,&g_pmt_cb);
//				drive_pwm_act(*((uint16_t*)buff),DRIVE_PWM_CLOSE,&g_pmt_cb);
			}
			break;
		case CMD_VALVE:
			if(*((uint16_t*)buff + 1))
				drive_dc_act(*((uint16_t*)buff),DRIVE_DC_OPEN_NCNT,&g_pmt_cb);
			else
				drive_dc_act(*((uint16_t*)buff),DRIVE_DC_CLOSE_NCNT,&g_pmt_cb);
			break;
		case CMD_SURFACE:
			surface_motor_index = p_cmd->id;
			plunger_capacity(p_plunger,PLUNGER_CAPACITY_THRESHOLD);
			motor_pos_asyn(p_cmd->id,DEFAULT_POS,p_cmd->pos);
			msg_post(MSG_SURFACE_CHECKING, NULL, &g_pmt_cb,&g_pmt_cb);
			break;
		case CMD_SUCK:
			while(!plunger_bus_enable())
			{
				rt_thread_delay(10);
			}
			plunger_pos(p_plunger,*((uint32_t*)buff));
			break;
		case CMD_RESET_TIP:
			while(!plunger_bus_enable())
			{
				rt_thread_delay(10);
			}
			plungnger_home(p_plunger);
			break;
		case CMD_LED:
			if(p_led->status == 0)
			{
				valve_low(p_led->id);
			}
			if(p_led->status == 1)
			{
				valve_high(p_led->id);
			}
			if(p_led->status == 2)
			{
				valve_toggle(p_led->id);
			}
			break;
		case CMD_MOTOR_DISABLE:
			for(uint8_t index = 0;index < MOTOR_NUM;index++)
			{
				motor_disable(index);
			}
			break;
		case CMD_QURY_ENC:
			for(uint8_t index = 0;index < MOTOR_NUM;index++)
			{
				enc_pos[index] = motor_read_enc(index);
			}
			tcp_transfer_push(RELY_QURY_ENC,enc_pos,sizeof(enc_pos));
			break;
		default:Critical_Log("Unknow tcp cmd!\r\n");
	}
}

static void claw_poll(uint64_t tick)
{
//	if(modbus_get_status(&m_modbus) != MODBUS_IDLE
//		|| tick%CLAW_POLL_TICK != 0)
//		return;
////	if(claw1->status == REG_STATUS_OPENING
////		|| claw1->status == REG_STATUS_CLOSING)
////	{
////		if(claw1->poll_tick == 0)
////		{}
////		else
////		{
////			claw_status(claw1);
////		}
////		claw1->poll_tick++;
////		return;
////	}
//	rt_thread_delay(10);
//	if(claw2->status == REG_STATUS_OPENING
//		|| claw2->status == REG_STATUS_CLOSING)
//	{
//		if(claw2->poll_tick == 0)
//		{}
//		else
//		{
//			claw_status(claw2);
//		}
//		claw2->poll_tick++;
//		return;
//	}
}
/*
*********************************************************************************************************
*					
*********************************************************************************************************
*/
static void pmt_task_process(void *p_arg)
{
	__IO uint64_t tick = 0;
	app_msg_t *p_msg = NULL;
	rt_err_t err;
	
	pmt_task_init();

	while(1)
	{
		if(RT_EOK != rt_mb_recv(&g_pmt_cb.mailbox,(rt_uint32_t*)&p_msg,MODULE_DEFAULT_WAKEUP)
			|| p_msg == NULL)
		{
			tick += MODULE_DEFAULT_WAKEUP;
			act_ticks(&g_pmt_cb.send_list);
			p_msg = NULL;
			claw_poll(tick);
			plunger_poll(tick);
			continue;
		}
		if(p_msg->event == MSG_DEFAULT_TMR)
		{
			act_ticks(&g_pmt_cb.send_list);
			app_msg_free(p_msg);
			continue;
		}
		if(MSG_PMT_HOME_CPLT == p_msg->event)
		{
			tcp_transfer_push(RPLY_HOME,NULL,0);
		}
		else if(MSG_SCAN_STOP == p_msg->event)
		{
			if(cr100_status() != CR100_IDLE)
			{
				cr100_start(CR100_IDLE);
				tcp_transfer_push(RPLY_SCAN,NULL,0);
			}
		}
		else if(MSG_RFID_STOP == p_msg->event)
		{
			if(rfid_busy())
			{
				rfid_reset();
				
				if(rfid_get_last_cmd() == RFID_READ)
				{
					tcp_transfer_push(RPLY_RFID,NULL,0);
				}
				else if(rfid_get_last_cmd() == RFID_WRITE)
				{
					uint16_t rtn = 0;
					tcp_transfer_push(RPLY_RFID_WRITE,&rtn,sizeof(rtn));
				}
	
			}
		}
//		else if(MSG_CLAW_QURY == p_msg->event)
//		{
//			claw_cmd_t claw_rply;
//			claw_t* p_claw;
//			claw_rply.claw_id = p_msg->data;
////			if(p_msg->data == 0)
////				p_claw = claw1;
////			else if(p_msg->data == 1)
//				p_claw = claw2;
//			if(p_claw != NULL && p_claw->status == REG_STATUS_CATCHED)
//				claw_rply.claw_status = 1;
//			else if(p_claw != NULL)
//				claw_rply.claw_status = 0;
//			tcp_transfer_push(RPLY_CLAW_STATUS,&claw_rply,sizeof(claw_rply));
//		}
		else if(MSG_SURFACE_CHECKING == p_msg->event)
		{
			uint16_t rlt = 0;
			if(motor_check_idle(surface_motor_index) != 1)
			{
				process_tmr(30,&g_pmt_cb);
				msg_post(MSG_SURFACE_CHECKING, NULL, &g_pmt_cb,&g_pmt_cb);
			}
			else
			{
				if(p_plunger->capacitance > PLUNGER_CAPACITY_THRESHOLD)
				{
					rlt = 1;
				}
				else
				{
					rlt = 0;
				}
				motor_t* p_motor = id_get_motor(surface_motor_index);
				uint16_t rtn_msg[3];
				rtn_msg[0] = rlt;
				*((int32_t*)&rtn_msg[1]) = p_motor->tar_pos;
				tcp_transfer_push(RPLY_SURFACE,&rtn_msg,sizeof(rtn_msg));
				plunger_capacity(p_plunger,0);
			}
		}
		switch(g_pmt_cb.status)
		{
			case MOD_STATUS_DISABLE:		disable_msg_proc(&g_pmt_cb,p_msg);break;
			case MOD_STATUS_UNINIT:			uninit_msg_proc(&g_pmt_cb,p_msg);break;
			case MOD_STATUS_IDLE:				idle_msg_proc(&g_pmt_cb,p_msg);break;
			case MOD_STATUS_SCHEDULE:		schedule_msg_proc(&g_pmt_cb,p_msg);break;
			case MOD_STATUS_CALIB:			calib_msg_proc(&g_pmt_cb,p_msg);break;
			case MOD_STATUS_MANUAL:			manual_msg_proc(&g_pmt_cb,p_msg);break;
			case MOD_STATUS_SWITCH:			switch_msg_proc(&g_pmt_cb,p_msg);break;
			case MOD_STATUS_ERROR:			error_msg_proc(&g_pmt_cb,p_msg);break;
			default:Error_Log("pmt task in illegal status!\r\n");break;
		}
		app_msg_free(p_msg);
	}
}
static void disable_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{
//	default_disable_msg_proc(p_tcb,p_msg);
}
static void uninit_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{
//	default_uninit_msg_proc(p_tcb,p_msg);
}
static void idle_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{
//	switch(p_msg->event)
//	{
//		default:default_idle_msg_proc(p_tcb,p_msg);break;
//	}
}
static void schedule_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{
//	switch(p_msg->event)
//	{
//		default:default_schedule_msg_proc(p_tcb,p_msg);break;
//	}	
}
/*���Թ���TBD*/
static void calib_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{	
//	switch(p_msg->event)
//	{
//		default:default_calib_msg_proc(p_tcb,p_msg);break;
//	}	
}
/*�ֶ�״̬�²��� ���ݲ�ͬģ�鹦�ܱ�д*/
static void manual_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{
//	default_manual_msg_proc(p_tcb,p_msg);
}
static void switch_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{
//	default_switch_msg_proc(p_tcb,p_msg);
}
/*����״̬ �������κ���Ϣ*/
static void error_msg_proc(schedule_cb_t * p_tcb,app_msg_t* p_msg)
{
//	default_err_msg_proc(p_tcb,p_msg);
}
/*����ģ���������*/
static void pmt_act_start(pmt_action_t act)
{
	tube_t* p_tube;
	g_pmt_cb.last_action = act;
	static reagent_ab_t* cur_rb = NULL;
	switch((uint32_t)act)
	{
		default:
			break;
	}
	msg_post(MSG_PMT_ACT_FINISH, act, &g_pmt_cb,&g_pmt_cb);
}
/*ģ�鶯����ɲ���*/
static void pmt_act_finish(pmt_action_t act)
{
	tube_t* p_tube;
	rt_base_t it = rt_hw_interrupt_disable();
	g_pmt_cb.last_action=act;
	switch(act){
		
		default:break;
	}
	rt_hw_interrupt_enable(it);
}